<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('列表')" />
</head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								渠道名称：<input type="text" name="channelName"/>
							</li>
							<li>
								商户名称：<input type="text" name="merchantName"/>
							</li>
							<li>
								支付类型：
								<select  id="payKindName" name="payKindName"></select>
							</li>
							<li>
								状态：<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}">
								<option value="">所有</option>
								<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
							</select>
							</li>

							<li>
								优先级：<input type="text" name="level"/>
							</li>

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="methodStatuSetting()">
					<i class="fa fa-edit"></i> 批量费率
				</a>
				<a class="btn btn-success" onclick="methodSwitchSetting()">
					<i class="fa fa-edit"></i> 批量开关
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="merchant:mpMerchantMethod:export">
						<i class="fa fa-download"></i> 导出
				 </a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('merchant:mpMerchantMethod:edit')}]];
        var removeFlag = [[${@permission.hasPermi('merchant:mpMerchantMethod:remove')}]];
        var prefix = ctx + "merchant/mpMerchantMethod";
		initSelect($("#channelMethodId"),"channel/channelInfo/list");

        $(function() {

            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                modalName: "商户支付方法",
		        showExport: true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'id', 
					title : '主键id',
					visible: false
				},
                {
                    field : 'merchantId',
                    title : '商户标识',
                    sortable: true,
                    visible: false
                },
                {
                    field : 'merchantName',
                    title : '商户名称',
                    sortable: true
                },
                {
                    field : 'channelName',
                    title : '渠道名称',
                    sortable: true
                },
                {
                    field : 'payKindName',
                    title : '支付类型'
                },
                {
                    field : 'walletKindName',
                    title : '钱包类型'
                },
				{
					field : 'channelMethodId',
					title : '渠道-支付方法标识',
					sortable: true,
                    visible: false
				},
                {
                    field : 'channelMethodPayRate',
                    title : '渠道-支付方法费率',
                    formatter: function (value, row, index) {
                        var data = value.toFixed(4);
                        return data;
                    }
                },
				{
					field : 'payRate', 
					title : '商户-支付方法费率',
					sortable: true,
                    formatter: function (value, row, index) {
                        var data = value.toFixed(4);
                        return data;
                    }
				},
				{
					field : 'level', 
					title : '优先级',
					sortable: true
				},
                {
                    visible: editFlag == 'hidden' ? false : true,
                    field : 'status',
                    title : '状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return merchantMethod_statusTools(row);
                    }
                },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>修改</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });


		// 初始化下拉菜单选项
		function initSelect(i,url) {
			$.post(ctx + url ,function (data) {
				var option = "<option value='' selected>所有</option>";
				$.each(data.rows,function (index,value) {
					option += "<option value='"+value.id+"'>"+value.name+"</option>";
				});
				i.html(option);
			});
		}

        /*支付类型下拉框*/
        $.post(ctx + "basedata/paykind/list", {'name':''},function (response) {
            var data = response.rows;
            var option = "<option value=''>" + "全部" + "</option>";
            for (var i = 0; i < data.length; i++) {
                option += "<option value='"+ data[i].name +"'>" + data[i].name + "</option>"
            }
            $("#formId").find("select[name='payKindName']").html("").append(option);
        });

		/**
		 *支付方法状态显示
		 */
		function merchantMethod_statusTools(row) {
			if (row.status == 1) {
				return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="merchantMethod_enable(\'' + row.id + '\')"></i> ';
			} else {
				return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="merchantMethod_disable(\'' + row.id + '\')"></i> ';
			}
		}

		/**
		 * 支付方法状态-停用
		 */
		function merchantMethod_disable(merchantMethodId) {
			$.modal.confirm("确认要停用所选支付方法吗？", function () {
				$.operate.post(prefix + "/changeStatus", {"id": merchantMethodId, "status": 1})
			});
		}

		/**
		 * 支付方法状态-启动
		 */
		function merchantMethod_enable(merchantMethodId) {
			$.modal.confirm("确认要启用所选支付方法吗？", function () {
				$.operate.post(prefix + "/changeStatus", {"id": merchantMethodId, "status": 0})
			});
		}


        /**
         * 支付方法 - 批量设置
         */
        function methodStatuSetting() {
            var url = prefix + '/methodStatuSetting';
            $.modal.open("设置开关", url);
        }


        /**
         * 商户支付方法 - 批量开关
         */
        function methodSwitchSetting() {
            var url = ctx + "merchant/merchantInfo" + '/methodSwitch';
            $.modal.open("批量开关", url);
        }



	</script>
</body>
</html>